<extend name="Public/base"/>

<!-- 子导航 -->
<block name="sidebar">
    <include file="Article/sidemenu" />
</block>

<block name="body">
	<!-- 标题 -->
	<div class="am-cf am-u-md-12 header-title">
		<h2>列表({$_total})</h2>
	</div>

	<!-- 按钮工具栏 -->
	<div class="am-cf am-g am-margin-top">
		<div class="am-cf am-u-md-7 am-btn-group">
			<a class="am-btn am-btn-primary" href="{:U('page/add',array('model_id'=>$model['id']))}">新 增</a>
            <button class="am-btn am-btn-success ajax-post" target-form="ids" url="{:U("Page/setStatus",array("status"=>1))}">启 用</button>
			<button class="am-btn am-btn-default ajax-post" target-form="ids" url="{:U("Page/setStatus",array("status"=>0))}">禁 用</button>
			<input type="hidden" class="hide-data" name="cate_id" value="{$cate_id}"/>
			<input type="hidden" class="hide-data" name="pid" value="{$pid}"/>
			<button class="am-btn am-btn-danger ajax-post confirm" target-form="ids" url="{:U("Page/setStatus",array("status"=>-1))}">删 除</button>
		</div>

		<!-- 高级搜索 -->
		<div class="search-form am-u-md-5 am-fr am-cf">
			<div class="am-input-group">
				<input type="text" name="title" class="am-form-field" value="{:I('title')}" placeholder="请输入标题文档">
				<span class="am-input-group-btn">
					<a class="am-btn am-btn-default" href="javascript:;" id="search" url="{:U('article/index','pid='.I('pid',0).'&cate_id='.$cate_id,false)}"><i class="am-icon am-icon-search"></i></a>
				</span>
			</div>
		</div>
	</div>

	<!-- 数据表格 -->
    <div class="am-cf am-u-md-12 am-margin-top">
		<table class="am-table am-table-striped">
            <!-- 表头 -->
            <thead>
                <tr>
                    <th class="row-selected row-selected">
                        <input class="check-all" type="checkbox">
                    </th>
                    <volist name="list_grids" id="field">
                        <th>{$field.title}</th>
                    </volist>
                </tr>
            </thead>

            <!-- 列表 -->
            <tbody>
                <volist name="list" id="data">
                    <tr>
                        <td><input class="ids" type="checkbox" value="{$data['id']}" name="ids[]"></td>
                        <volist name="list_grids" id="grid">
                            <td>{:get_page_list_field($data,$grid)}</td>
                        </volist>
                    </tr>
                </volist>
            </tbody>
        </table>
	</div>
	<!-- 分页 -->
    <div class="am-cf am-u-md-12">
        {$_page}
    </div>

</block>
<block name="script">
<link href="__PUBLIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__PUBLIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__PUBLIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__PUBLIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
$(function(){
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
		var status = $("#sch-sort-txt").attr("data");
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
		if(status != ''){
			query = 'status=' + status + "&" + query;
        }
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});

	/* 状态搜索子菜单 */
	$(".search-form").find(".drop-down").hover(function(){
		$("#sub-sch-menu").removeClass("hidden");
	},function(){
		$("#sub-sch-menu").addClass("hidden");
	});
	$("#sub-sch-menu li").find("a").each(function(){
		$(this).click(function(){
			var text = $(this).text();
			$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
			$("#sub-sch-menu").addClass("hidden");
		})
	});

	//只有一个模型时，点击新增
	$('.document_add').click(function(){
		var url = $(this).attr('url');
		if(url != undefined && url != ''){
			window.location.href = url;
		}
	});

	//点击排序
	$('.list_sort').click(function(){
		var url = $(this).attr('url');
		var ids = $('.ids:checked');
		var param = '';
		if(ids.length > 0){
			var str = new Array();
			ids.each(function(){
				str.push($(this).val());
			});
			param = str.join(',');
		}

		if(url != undefined && url != ''){
			window.location.href = url + '/ids/' + param;
		}
	});

    //回车自动提交
    $('.search-form').find('input').keyup(function(event){
        if(event.keyCode===13){
            $("#search").click();
        }
    });

    $('#time-start').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });

    $('#time-end').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
	    minView:2,
	    autoclose:true
    });
})
</script>
</block>